<template>
  <div class="time-picker-examples">
    <!-- 示例1: 基础用法 -->
    <div class="example">
      <h3>基础用法</h3>
      <TimePicker
        v-model:value="time1"
        v-model:visible="visible1"
        @change="handleChange1"
        @open="handleOpen1"
        @close="handleClose1"
      />
      <div class="selected-time">已选择时间: {{ time1 || '未选择' }}</div>
    </div>

    <!-- 示例2: 显示秒数 -->
    <div class="example">
      <h3>显示秒数</h3>
      <TimePicker
        v-model:value="time2"
        v-model:visible="visible2"
        format="HH:mm:ss"
        :show-seconds="true"
        @change="handleChange2"
        @open="handleOpen2"
        @close="handleClose2"
      />
      <div class="selected-time">已选择时间: {{ time2 || '未选择' }}</div>
    </div>

    <!-- 示例3: 禁用时间 -->
    <div class="example">
      <h3>禁用部分时间</h3>
      <TimePicker
        v-model:value="time3"
        :disabled-hours="disabledHours3"
        :disabled-minutes="disabledMinutes3"
        :disabled-seconds="disabledSeconds3"
        :show-seconds="true"
        @change="handleChange3"
      />
      <div class="selected-time">已选择时间: {{ time3 || '未选择' }}</div>
      <div class="disabled-info">
        <p>禁用小时: 1,2,3点</p>
        <p>禁用分钟: 小于30分</p>
        <p>禁用秒数: 奇数秒</p>
      </div>
    </div>

    <!-- 示例4: 不同位置和尺寸 -->
    <div class="example">
      <h3>顶部弹出+大尺寸</h3>
      <TimePicker
        v-model:value="time4"
        v-model:visible="visible4"
        placement="top"
        size="large"
        @change="handleChange4"
        @open="handleOpen4"
        @close="handleClose4"
      />
      <div class="selected-time">已选择时间: {{ time4 || '未选择' }}</div>
    </div>

    <!-- 示例5: 自定义样式 -->
    <div class="example">
      <h3>自定义样式</h3>
      <TimePicker
        v-model:value="time5"
        v-model:visible="visible5"
        @change="handleChange5"
      >
        <template #trigger>
          <button class="custom-trigger">
            {{ time5 || '选择时间' }}
          </button>
        </template>
        <template #footer>
          <div class="custom-footer">
            <button class="btn-cancel" @click="handleCancel5">取消</button>
            <button class="btn-confirm" @click="handleConfirm5">确定</button>
          </div>
        </template>
      </TimePicker>
      <div class="selected-time">已选择时间: {{ time5 || '未选择' }}</div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import TimePicker from '@/components/TimePicker/TimePicker.vue'

// 示例1数据和方法
const time1 = ref('')
const visible1 = ref(false)
const handleChange1 = (val) => {
  console.log('时间变化:', val)
}
const handleOpen1 = () => {
  console.log('时间选择器打开')
}
const handleClose1 = () => {
  console.log('时间选择器关闭')
}

// 示例2数据和方法
const time2 = ref('14:30:00')
const visible2 = ref(false)
const handleChange2 = (val) => {
  console.log('带秒数的时间变化:', val)
}
const handleOpen2 = () => {
  console.log('带秒数时间选择器打开')
}
const handleClose2 = () => {
  console.log('带秒数时间选择器关闭')
}

// 示例3数据和方法
const time3 = ref('')
const disabledHours3 = () => [1, 2, 3]
const disabledMinutes3 = (hour) => {
  const minutes = []
  for (let i = 0; i < 30; i++) {
    minutes.push(i)
  }
  return minutes
}
const disabledSeconds3 = () => {
  const seconds = []
  for (let i = 0; i < 60; i++) {
    if (i % 2 !== 0) seconds.push(i)
  }
  return seconds
}
const handleChange3 = (val) => {
  console.log('禁用时间示例变化:', val)
}

// 示例4数据和方法
const time4 = ref('')
const visible4 = ref(false)
const handleChange4 = (val) => {
  console.log('大尺寸时间选择:', val)
}
const handleOpen4 = () => {
  console.log('顶部弹出时间选择器打开')
}
const handleClose4 = () => {
  console.log('顶部弹出时间选择器关闭')
}

// 示例5数据和方法
const time5 = ref('')
const visible5 = ref(false)
const handleChange5 = (val) => {
  console.log('自定义样式时间变化:', val)
}
const handleConfirm5 = () => {
  visible5.value = false
  console.log('确认选择时间:', time5.value)
}
const handleCancel5 = () => {
  visible5.value = false
  time5.value = ''
  console.log('取消选择时间')
}
</script>

<style scoped>
.time-picker-examples {
  padding: 20px;
}

.example {
  margin-bottom: 30px;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 8px;
  background-color: #fff;
}

h3 {
  margin-bottom: 15px;
  color: #333;
}

.selected-time {
  margin-top: 10px;
  color: #666;
  font-size: 14px;
}

.disabled-info {
  margin-top: 10px;
  font-size: 12px;
  color: #999;
}

.custom-trigger {
  padding: 8px 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.custom-trigger:hover {
  background-color: #45a049;
}

.custom-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px;
}

.custom-footer button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-cancel {
  background-color: #f44336;
  color: white;
}

.btn-confirm {
  background-color: #4CAF50;
  color: white;
}

.btn-cancel:hover {
  background-color: #da190b;
}

.btn-confirm:hover {
  background-color: #45a049;
}
</style>